package com.ruoyi.huanjing.entity.dto;

import com.ruoyi.huanjing.entity.DataBlock;

import java.util.Arrays;

/**
 * 基础数据块DTO（X-Y轴格式）
 */
public class BasicDataDTO {
    private double[] xAxis;
    private double[] yAxis;

    public static BasicDataDTO fromDataBlock(DataBlock dataBlock) {
        BasicDataDTO dto = new BasicDataDTO();
        if (dataBlock == null || dataBlock.getData().length < 2) {
            dto.setXAxis(new double[0]);
            dto.setYAxis(new double[0]);
            return dto;
        }

        int n = Math.min(dataBlock.getLength(), dataBlock.getData().length / 2);
        dto.setXAxis(Arrays.copyOfRange(dataBlock.getData(), 0, n));
        dto.setYAxis(Arrays.copyOfRange(dataBlock.getData(), n, Math.min(2 * n, dataBlock.getData().length)));
        return dto;
    }

    // Getter & Setter
    public double[] getXAxis() { return xAxis; }
    public void setXAxis(double[] xAxis) { this.xAxis = xAxis; }
    public double[] getYAxis() { return yAxis; }
    public void setYAxis(double[] yAxis) { this.yAxis = yAxis; }
}